package com.wb.mas.data;


import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;

import com.wb.mas.data.source.HttpDataSource;
import com.wb.mas.data.source.LocalDataSource;
import com.wb.mas.entity.ApproveResponse;
import com.wb.mas.entity.AuthBackResponse;
import com.wb.mas.entity.BackStatusResponse;
import com.wb.mas.entity.BankResponse;
import com.wb.mas.entity.BannerResponse;
import com.wb.mas.entity.CalculateRateResponse;
import com.wb.mas.entity.DeferInfoResponse;
import com.wb.mas.entity.DicInfoResponse;
import com.wb.mas.entity.FaceCompareResponse;
import com.wb.mas.entity.HelpResponse;
import com.wb.mas.entity.IdentityInfoResponse;
import com.wb.mas.entity.LoginResponse;
import com.wb.mas.entity.LoginTypeResponse;
import com.wb.mas.entity.OrderDetailResponse;
import com.wb.mas.entity.OrderListResponse;
import com.wb.mas.entity.OrderPageResponse;
import com.wb.mas.entity.OrderResponse;
import com.wb.mas.entity.PayCodeResponse;
import com.wb.mas.entity.ProDetailResponse;
import com.wb.mas.entity.RemindInfoResponse;
import com.wb.mas.entity.RootApiBean;
import com.wb.mas.entity.SubmitedAuthResponse;
import com.wb.mas.entity.UploadImageResponse;
import com.wb.mas.entity.VersionResponse;

import java.io.File;
import java.util.Map;

import io.reactivex.Observable;
import me.goldze.mvvmhabit.base.BaseModel;

/**
 * MVVM的Model层，统一模块的数据仓库，包含网络数据和本地数据（一个应用可以有多个Repositor）
 * Created by goldze on 2019/3/26.
 */
public class DemoRepository extends BaseModel implements HttpDataSource, LocalDataSource {
    private volatile static DemoRepository INSTANCE = null;
    private final HttpDataSource mHttpDataSource;

    private final LocalDataSource mLocalDataSource;

    private DemoRepository(@NonNull HttpDataSource httpDataSource,
                           @NonNull LocalDataSource localDataSource) {
        this.mHttpDataSource = httpDataSource;
        this.mLocalDataSource = localDataSource;
    }

    public static DemoRepository getInstance(HttpDataSource httpDataSource,
                                             LocalDataSource localDataSource) {
        if (INSTANCE == null) {
            synchronized (DemoRepository.class) {
                if (INSTANCE == null) {
                    INSTANCE = new DemoRepository(httpDataSource, localDataSource);
                }
            }
        }
        return INSTANCE;
    }

    @VisibleForTesting
    public static void destroyInstance() {
        INSTANCE = null;
    }
    @Override
    public Observable<LoginResponse> login(Map<String, Object> map) {
        return mHttpDataSource.login(map);
    }

    @Override
    public Observable<BannerResponse> getBanner(Map<String, Object> params) {
        return mHttpDataSource.getBanner(params);
    }

    @Override
    public Observable<ProDetailResponse> getProdDeailList(Map<String, Object> params) {
        return mHttpDataSource.getProdDeailList(params);
    }

    @Override
    public Observable<CalculateRateResponse> calculateRate(Map<String, Object> params) {
        return mHttpDataSource.calculateRate(params);
    }

    @Override
    public Observable<RootApiBean> checkOrderQualifications(Map<String, Object> params) {
        return mHttpDataSource.checkOrderQualifications(params);
    }

    @Override
    public Observable<ApproveResponse> getApproveStatus(Map<String, Object> params) {
        return mHttpDataSource.getApproveStatus(params);
    }

    @Override
    public Observable<RootApiBean> createOrder(Map<String, Object> params) {
        return mHttpDataSource.createOrder(params);
    }

    @Override
    public Observable<RootApiBean> uploadPhone(Map<String, Object> params, File file) {
        return mHttpDataSource.uploadPhone(params, file);
    }

    @Override
    public Observable<RootApiBean> saveLngLat(Map<String, Object> params) {
        return mHttpDataSource.saveLngLat(params);
    }

    @Override
    public Observable<UploadImageResponse> uploadImage(Map<String, Object> params, File file) {
        return mHttpDataSource.uploadImage(params, file);
    }

    @Override
    public Observable<FaceCompareResponse> faceCompare(Map<String, Object> params) {
        return mHttpDataSource.faceCompare(params);
    }

    @Override
    public Observable<RootApiBean> updateOrSaveUser(Map<String, Object> params) {
        return mHttpDataSource.updateOrSaveUser(params);
    }

    @Override
    public Observable<DicInfoResponse> getDicInfo(Map<String, Object> params) {
        return mHttpDataSource.getDicInfo(params);
    }

    @Override
    public Observable<RootApiBean> saveOrUpdateCustomerInfo(Map<String, Object> params) {
        return mHttpDataSource.saveOrUpdateCustomerInfo(params);
    }

    @Override
    public Observable<RootApiBean> saveOrUpdateContactsInfo(Map<String, Object> params) {
        return mHttpDataSource.saveOrUpdateContactsInfo(params);
    }

    @Override
    public Observable<IdentityInfoResponse> getIdentityInfo(Map<String, Object> params) {
        return mHttpDataSource.getIdentityInfo(params);
    }

    @Override
    public Observable<RootApiBean> saveOrUpdateBankList(Map<String, Object> params) {
        return mHttpDataSource.saveOrUpdateBankList(params);
    }

    @Override
    public Observable<RootApiBean> imageInformation(Map<String, Object> params) {
        return mHttpDataSource.imageInformation(params);
    }

    @Override
    public Observable<OrderResponse> getOrderInfoList(Map<String, Object> params) {
        return mHttpDataSource.getOrderInfoList(params);
    }

    @Override
    public Observable<OrderPageResponse> getOrderInfoPage(Map<String, Object> params) {
        return mHttpDataSource.getOrderInfoPage(params);
    }

    @Override
    public Observable<BankResponse> getBankDetail(Map<String, Object> params) {
        return mHttpDataSource.getBankDetail(params);
    }

    @Override
    public Observable<PayCodeResponse> getPayCode(Map<String, Object> params) {
        return mHttpDataSource.getPayCode(params);
    }

    @Override
    public Observable<RootApiBean> rolloverApp(Map<String, Object> params) {
        return mHttpDataSource.rolloverApp(params);
    }

    @Override
    public Observable<DeferInfoResponse> getDeferInfo(Map<String, Object> params) {
        return mHttpDataSource.getDeferInfo(params);
    }

    @Override
    public Observable<PayCodeResponse> getDeferPayCode(Map<String, Object> params) {
        return mHttpDataSource.getDeferPayCode(params);
    }

    @Override
    public Observable<BackStatusResponse> getBackStatus(Map<String, Object> params) {
        return mHttpDataSource.getBackStatus(params);
    }

    @Override
    public Observable<HelpResponse> getHelpDatas(Map<String, Object> params) {
        return mHttpDataSource.getHelpDatas(params);
    }

    @Override
    public Observable<LoginResponse> loginByUserNameAndPassword(Map<String, Object> params) {
        return mHttpDataSource.loginByUserNameAndPassword(params);
    }


    @Override
    public Observable<SubmitedAuthResponse> getSubmitedAuthInfo(Map<String, Object> params) {
        return mHttpDataSource.getSubmitedAuthInfo(params);
    }

    @Override
    public Observable<AuthBackResponse> getSubmitedBankInfo(Map<String, Object> params) {
        return mHttpDataSource.getSubmitedBankInfo(params);
    }

    @Override
    public Observable<RemindInfoResponse> getRemindInfo(Map<String, Object> params) {
        return mHttpDataSource.getRemindInfo(params);
    }

    @Override
    public Observable<OrderListResponse> getOrderPageList(Map<String, Object> params) {
        return mHttpDataSource.getOrderPageList(params);
    }

    @Override
    public Observable<OrderDetailResponse> getOrderDetail(Map<String, Object> params) {
        return mHttpDataSource.getOrderDetail(params);
    }

    @Override
    public Observable<RootApiBean> getSmsCode(Map<String, Object> params) {
        return mHttpDataSource.getSmsCode(params);

    }

    @Override
    public Observable<LoginResponse> loginByPhoneCode(Map<String, Object> params) {
        return mHttpDataSource.loginByPhoneCode(params);

    }

    @Override
    public Observable<LoginTypeResponse> getLoginType(Map<String, Object> params) {
        return mHttpDataSource.getLoginType(params);

    }
}
